from pydantic import BaseModel, Field
from typing import Optional, List
from app.schemas.base import BaseSchema

class PermissionBase(BaseModel):
    """权限基础模式"""
    name: str = Field(..., description="权限名称")
    code: str = Field(..., description="权限编码")
    type: str = Field(..., description="权限类型：menu-菜单，button-按钮")
    parent_id: Optional[int] = Field(None, description="父权限ID")
    path: Optional[str] = Field(None, description="路由路径")
    component: Optional[str] = Field(None, description="组件路径")
    icon: Optional[str] = Field(None, description="图标")
    sort: int = Field(0, description="排序")
    status: bool = Field(True, description="状态：True-启用，False-禁用")

class PermissionCreate(PermissionBase):
    """创建权限模式"""
    pass

class PermissionUpdate(PermissionBase):
    """更新权限模式"""
    name: Optional[str] = Field(None, description="权限名称")
    code: Optional[str] = Field(None, description="权限编码")
    type: Optional[str] = Field(None, description="权限类型")

class PermissionInDB(PermissionBase, BaseSchema):
    """数据库中的权限模式"""
    pass

class PermissionOut(PermissionInDB):
    """权限输出模式"""
    children: List["PermissionOut"] = Field(default=[], description="子权限列表")

# 解决循环引用问题
PermissionOut.update_forward_refs()